<template>
  <page-header-wrapper :title="false">
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="queryParam.queryCondition" allow-clear placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="日期">
                <a-range-picker v-model="queryParam.date" format="YYYY-MM-DD" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" :loading="loading" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :pagination="pagination"
        @change="handleTableChange"
        :columns="columns"
        :data-source="loadData"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="status" slot-scope="text, record">
          <template>
            <a-tag color="#82af6f" v-if="record?.status == 1">盈利</a-tag>
            <a-tag color="#D15B47" v-else>亏</a-tag>
          </template>
        </span>
        <span slot="action" slot-scope="text, record">
          <template> {{ record.name }} <a-tag color="#428bca" @click="handleDetail(record)">详情</a-tag> </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>
      
      <script>
import { getMyOrderListUsingPOST } from '@/api/api/qiantaizhangwu.ts'
import moment from 'moment'
import { omit } from 'lodash-es'
export default {
  name: 'InventoryRecordList',
  data() {
    return {
      mdl: null,
      visible: false,
      value: '',
      value4: '',
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      pagination: {
        total: 0,
      },
      loading: false,
      queryParam: {
        pageNo: 1,
        pageSize: 10,
        queryCondition: '',
        date: [moment().startOf('months').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')],
        status: '',
      },
      // 表头
      columns: [
        {
          title: '入库日期',
          dataIndex: 'orderDate',
        },
        {
          title: '商品名',
          dataIndex: 'no3',
        },
        {
          title: '串码',
          dataIndex: 'code',
        },

        {
          title: '串码2',
          dataIndex: 'code2',
        },
        {
          title: '成本',
          dataIndex: 'chengben',
        },
        {
          title: '考核成本',
          dataIndex: 'khChengben',
        },
        {
          title: '供应商',
          dataIndex: 'supplyName',
        },
        {
          title: '在库情况',
          dataIndex: 'desc',
        },
        {
          title: '状态',
          dataIndex: 'status',
          scopedSlots: { customRender: 'status' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: [
        {
          id: 1,
          inventoryId:'1',
          orderDate: '2023-09-13 15:18',
          no3: '测试001-01-商品',
          code: 'H94852G7254',
          code2: '',
          chengben:'-8',
          khChengben:'0',
          supplyName:'测试',
          desc: '在库 达臻东街店',
          status:0
        },
        {
          id: 2,
          inventoryId:'2',
          orderDate: '2023-09-15 15:18',
          no3: '测试001-01-商品',
          code: 'H24053G50236',
          code2: '',
          chengben:'3.5',
          khChengben:'0',
          supplyName:'测试',
          desc: '在库 达臻东街店',
          status:0
        },
      ],
    }
  },
  mounted() {
    this.handleSearch(this.queryParam)
  },
  methods: {
    handleDetail(record) {
      this.$router.push({ path: `/goods/name/${record.inventoryId}` })
    },
    handleSearch(val) {
      this.loading = true
      setTimeout(() => {
        this.loading = false
      }, 1000)
      //   const params = {
      //     ...val,
      //     empId: 1,
      //     orderStatus: 2,
      //     startTime: val?.date?.[0] ? moment(val?.date?.[0]).format('YYYY-MM-DD') : null,
      //     endTime: val?.date?.[1] ? moment(val?.date?.[1]).format('YYYY-MM-DD') : null,
      //   }
      //   getMyOrderListUsingPOST({ ...omit(params, ['date']) })
      //     .then((res) => {
      //       this.loadData = res.data.list
      //       this.loading = false
      //       this.queryParam.pageNo = this.pagination.current
      //       this.pagination = { ...this.pagination, total: Number(res.data.total) }
      //     })
      //     .catch((error) => {
      //       this.loading = false
      //       this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
      //     })
    },
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.pagination }
      pager.current = pagination.current
 pager.pageSize = pagination.pageSize
      this.pagination = pager
      this.handleSearch({
        sortField: sorter.field,
        sortOrder: sorter.order,
        ...filters,
        pageNo: pagination.current,
        pageSize: pagination.pageSize,
        queryCondition: this.queryParam.queryCondition,
        status: this.queryParam.status,
        date: this.queryParam.date,
      })
    },
  },
}
</script>